﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using JN.Utility;

namespace Power.Common.Notify
{
    public partial class NotifyForm : DevExpress.XtraEditors.XtraForm
    {
        #region property
        private int waitTimerMaxCount = 15;
        private int waitCount = 0;
        public bool IsAutoClose { get; set; }
        public string MessageCate { get; set; }
        public string MessageInfo { get; set; }
        
        #endregion
        public NotifyForm()
        {
            InitializeComponent();
        }

        private void NotifyForm_Load(object sender, EventArgs e)
        {
            //display msg
            DisplayMessage();
        }
        private void DisplayMessage()
        {
            try
            {
                this.txtMsgCate.Text = MessageCate;
                this.txtMsgInfo.Text = MessageInfo;
                //timer1.Enabled = true;
                Application.DoEvents();
            }
            catch (Exception ex)
            {
                SystemLogger.Write(ex);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (IsAutoClose)
                {
                    //is auto close
                    if(waitCount >=waitTimerMaxCount) this.Close();
                    this.btnOk.Text = "确认(" + (waitTimerMaxCount - waitCount) + ")";
                    waitCount++;
                }
            }
            catch (Exception ex)
            {
                SystemLogger.Write(ex);
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.Close();
        }        
    }
}